'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const InterviewSchedule = app.model.define('interview_schedule', {
    schedule_id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: '日程编号',
    },
    user_id: {
      type: INTEGER,
      allowNull: false,
      comment: '候选人用户编号',
    },
    company_id: {
      type: INTEGER,
      allowNull: false,
      comment: '企业编号',
    },
    company_name: {
      type: STRING(100),
      allowNull: true,
      comment: '公司名称',
    },
    position_id: {
      type: INTEGER,
      allowNull: true,
      comment: '岗位编号',
    },
    position_name: {
      type: STRING(100),
      allowNull: true,
      comment: '岗位名称',
    },
    start_time: {
      type: DATE,
      allowNull: false,
      comment: '开始时间',
    },
    location: {
      type: STRING(200),
      allowNull: true,
      comment: '地点',
    },
    contact_person: {
      type: STRING(50),
      allowNull: true,
      comment: '联系人',
    },
    contact_phone: {
      type: STRING(20),
      allowNull: true,
      comment: '联系电话',
    },
    status: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '状态 1-待进行 2-进行中 3-已完成 4-已取消',
    },
    created_at: {
      type: DATE,
      allowNull: false,
      comment: '创建时间',
    },
  }, {
    tableName: 'interview_schedule',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: false,
    comment: '面试日程表',
  });

  // 关联关系
  InterviewSchedule.associate = function() {
    // 关联候选人用户
    app.model.InterviewSchedule.belongsTo(app.model.User, {
      foreignKey: 'user_id',
      targetKey: 'id',
      as: 'candidate'
    });
  };

  return InterviewSchedule;
};
